<template>
  <div class="upopusbox">
    <div class="main1">
      <h1 class="title">上传我做的{{ title1 }}星巴克同款</h1>
      <div class="filebox">
        <span class="name1">在电脑里面查找</span>
        <div>
          <input type="file" ref="file1" />
          <p class="tishi" ref="warn">请选择不超过4M的图片</p>
        </div>
      </div>
      <div class="saybox">
        <span class="name1">心得</span>
        <div contenteditable="true" class="say" ref="say"></div>
      </div>
      <div class="upbtn" @click="fup()">上传作品</div>
    </div>
    <p class="tishi right">
      请尊重创作者的劳动，<br />上传自己原创的作品信息。
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title1: "",
    };
  },
  mounted() {
    // 根据菜谱id获取菜谱信息
    this.$axios("/wxw/menuinfo", {
      params: {
        id: this.$route.params.cookid,
      },
    }).then((res) => {
      this.title1 = res.data[0].title;
    });
  },
  methods: {
    fup() {
      let dt = new Date();
      let pushtime = `${dt.getFullYear()}/${dt.getMonth() + 1}/${dt.getDate()}`;
      let fileinfo = this.$refs.file1.files[0];
      if (fileinfo.size / 1024 / 1024 < 4) {
        var formdata = new FormData();
        formdata.append("file1", fileinfo);
        formdata.append("say", this.$refs.say.innerText);
        formdata.append("title", this.title1);
        formdata.append("pushtime", pushtime);
        this.$axios.post("/wxw/waddopus", formdata);
      } else {
        this.$refs.warn.style.color = "red";
      }
    },
  },
};
</script>


<style scoped lang="scss">
.upopusbox {
  width: 1000px;
  margin: 0 auto;
  color: #222;
  font-size: 16px;
  position: relative;
  .main1 {
    width: 700px;
    .title {
      font-weight: bolder;
      letter-spacing: 3px;
      margin: 30px 0 60px;
    }
    .filebox {
      display: flex;
      line-height: 30px;
    }
    .saybox {
      display: flex;
      .say {
        width: 450px;
        min-height: 200px;
        border: 1px solid #eee;
        outline: none;
        padding: 10px;
      }
    }
    .name1 {
      width: 70px;
      text-align: right;
      margin-right: 20px;
      margin-bottom: 20px;
    }
    .upbtn {
      display: inline-block;
      background-color: #dd3915;
      color: #fff;
      padding: 7.5px 30px;
      margin: 50px 30px;
      cursor: pointer;
    }
  }
  .right {
    position: absolute;
    top: 100px;
    right: 160px;
    line-height: 24px;
  }
}
.tishi {
  font-size: 14px;
  color: #909090;
}
</style>